package org.example.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAdvice {

    @Pointcut( "execution(* org.example.service.BrandService.lookUp())")
    private void pt(){
    }
//    @Before("pt()")
//    public void method(){
//        System.out.println("你好");
//    }
//
//    , JoinPoint jp pjp的父类
    @Around("pt()")
    public Object testThousrendsTimes(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object proceed1;
        proceed1 = proceedingJoinPoint.proceed();
        long l = System.currentTimeMillis();
        for (int i=0;i<10000;i++){
             proceed1= proceedingJoinPoint.proceed();
        }
        Object[] args = proceedingJoinPoint.getArgs();
        System.out.println(args.toString());
        long l1 = System.currentTimeMillis();
        System.out.println("运行时间是"+(l1-l));
        return proceed1;

    }
}
